Method and apparatus to facilitate testing of garbage collection implementations

ABSTRACT

One embodiment of the present invention provides a system to facilitate testing of garbage collection implementations. The system operates by first receiving a trace of valid memory transactions at a test harness. This trace of valid memory transactions is replayed through the test harness into a memory manager, which includes a garbage collection implementation under test. The results of replaying this trace are then observed to verify that the garbage collection implementation under test does not erroneously change the contents of the memory.

BACKGROUND

[0001] 1. Field of the Invention

[0002] The present invention relates to garbage collection within computer memory. More specifically, the present invention relates to a method and an apparatus to facilitate testing of garbage collection implementations within a computer memory.

[0003] 2. Related Art

[0004] Many modern computing systems and languages rely upon garbage collectors to reclaim unused storage. A garbage collector relieves the programmer from the task of deallocating storage that is no longer needed for the execution of a program, and thereby makes more efficient use of the memory within the computing system.

[0005] While garbage collectors are desired within these computing systems, the garbage collector is frequently one of the largest, and most complex, software modules in the computing system. Errors in the garbage collector, however, may be very difficult to detect because these errors can manifest themselves in other program code that may be executed long after the garbage collector performs the erroneous actions that give rise to the errors. This delay between error occurrence and error manifestation makes debugging and testing garbage collectors a very difficult task. Additionally, errors within a platform-independent virtual machine, or in computer code executing on the platform-independent virtual machine, may cause errors that appear to originate within the garbage collector, thereby causing debugging efforts to be incorrectly allocated.

[0006] An additional problem with debugging a garbage collector is that a particular error may manifest itself differently, or in different places in the platform-independent virtual machine. The way an error manifests itself can depend upon non-deterministic factors such as which programs are running on the platform-independent virtual machine or differences in program execution speed caused by non-deterministic interactions with external resources.

[0007] What is needed is a method and an apparatus that facilitates testing a garbage collection implementation while eliminating the problems described above.

SUMMARY

[0008] One embodiment of the present invention provides a system to facilitate testing of garbage collection implementations. The system operates by first receiving a trace of valid memory transactions at a test harness. This trace of valid memory transactions is replayed through the test harness into a memory manager, which includes a garbage collection implementation under test. The results of replaying this trace are then observed to verify that the garbage collection implementation under test does not erroneously change the contents of the memory.

[0009] In one embodiment of the present invention, the trace of valid memory transactions includes memory transactions associated with multiple platform-independent computer programs concurrently executing on a platform-independent virtual machine.

[0010] In one embodiment of the present invention, the test harness includes an interface for each entry point into the memory manager.

[0011] In one embodiment of the present invention, a second garbage collection implementation under test is substituted for the garbage collection implementation under test.

[0012] In one embodiment of the present invention, verifying that the garbage collection implementation under test does not incorrectly change the content of the memory includes comparing the current state of the memory with the recorded state of memory stored with the trace of valid memory transactions.

[0013] In one embodiment of the present invention, the trace of valid memory transactions is gathered using a tracing platform-independent virtual machine.

[0014] In one embodiment of the present invention, the tracing platform-independent virtual machine is known to operate correctly.

BRIEF DESCRIPTION OF THE FIGURES

[0015]FIG. 1 illustrates computing device 100 including platform-independent virtual machine 102 in accordance with an embodiment of the present invention.

[0016]FIG. 2 illustrates computing device 100 including test harness 202 in accordance with an embodiment of the present invention.

[0017]FIG. 3 illustrates test harness 202 in accordance with an embodiment of the present invention.

[0018]FIG. 4 is a flowchart illustrating the process of testing a garbage collector in accordance with an embodiment of the present invention.

DETAILED DESCRIPTION

[0019] The following description is presented to enable any person skilled in the art to make and use the invention, and is provided in the context of a particular application and its requirements. Various modifications to the disclosed embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other embodiments and applications without departing from the spirit and scope of the present invention. Thus, the present invention is not intended to be limited to the embodiments shown, but is to be accorded the widest scope consistent with the principles and features disclosed herein.

[0020] The data structures and code described in this detailed description are typically stored on a computer readable storage medium, which may be any device or medium that can store code and/or data for use by a computer system. This includes, but is not limited to, magnetic and optical storage devices such as disk drives, magnetic tape, CDs (compact discs) and DVDs (digital versatile discs or digital video discs), and computer instruction signals embodied in a transmission medium (with or without a carrier wave upon which the signals are modulated). For example, the transmission medium may include a communications network, such as the Internet.

[0021] Creating a Trace of Valid Memory Transactions

[0022]FIG. 1 illustrates computing device 100, including platform-independent virtual machine 102, in accordance with an embodiment of the present invention. Computing device 100 can generally include any type of computer system, including, but not limited to, a computer system based on a microprocessor, a mainframe computer, a digital signal processor, a portable computing device, a personal organizer, a device controller, and a computational engine within an appliance.

[0023] Platform-independent virtual machine 102 includes memory manager 106 and garbage collector 108. Platform-independent virtual machine 102, memory manager 106, and garbage collector 108 are known to operate correctly. Platform-independent virtual machine 102 has been transformed into a tracing platform-independent virtual machine by the addition of tracing mechanism 104 at the interface between platform-independent virtual machine 102 and memory manager 106.

[0024] Tracing mechanism 104 monitors all memory transactions between platform-independent virtual machine 102 and memory manager 106. Additionally, tracing mechanism 104 monitors the state of memory in response to transactions from platform-independent virtual machine 102 and in response to garbage collection cycles by garbage collector 108. Tracing mechanism 104 stores these valid memory transactions and results in trace storage 110. In one implementation of the present invention, tracing mechanism 104 captures all read transactions from memory manager 106 and the returned results of these read operations and stores both the read transactions and the returned results in trace storage 110.

[0025] Trace storage 110 can include any type of system for storing data in non-volatile storage. This includes, but is not limited to, systems based upon magnetic, optical, and magneto-optical storage devices, as well as storage devices based on flash memory and/or battery-backed up memory.

[0026] Garbage collector 108 periodically reclaims unused storage that was allocated by platform-independent programs running on platform-independent virtual machine 102. Triggering a garbage collection cycle is a well-known procedure in the art and will not be discussed further herein. Tracing mechanism 104 monitors changes in memory caused by garbage collector 108 and stores the results in trace storage 110.

[0027] Replaying a Trace of Valid Memory Transactions

[0028]FIG. 2 illustrates computing device 100 including test harness 202 in accordance with an embodiment of the present invention. Test harness 202 includes the interfaces normally found between platform-independent virtual machine 102 and memory manager 106. Test harness 202 receives the trace of valid memory transactions from trace storage 110 and replays this trace of valid memory transaction into memory manager 106.

[0029] Memory manager 106 includes garbage collector under test 204. Any garbage collector that has the same interface as garbage collector 108 may be plugged into memory manager 106 as garbage collector under test 204, thereby making test harness 202 a useful tool for testing many implementations of garbage collectors.

[0030] Test harness 202 monitors the memory transactions caused by the trace of valid memory transactions and the actions of garbage collector under test 204 to verify that garbage collector under test 204 provides the same, correct, data as garbage collector 108. Testing with a trace of valid memory transactions instead of actual virtual machine execution simplifies the debugging process, because it removes all other causes of error, and focuses on only the garbage collection system.

[0031] Test Harness 202

[0032]FIG. 3 illustrates test harness 202 in accordance with an embodiment of the present invention. Test harness 202 includes receiving mechanism 302, replaying mechanism 304, observing mechanism 306, verifying mechanism 308, and memory interface 310.

[0033] In operation, receiving mechanism 302 receives the trace of valid memory transactions from trace storage 110. Replaying mechanism 304 replays these valid memory transactions through memory interface 310 into memory manager 106 to provide known changes to the memory so that garbage collector under test 204 has a known memory state.

[0034] Observing mechanism 306 observes the results of garbage collector under test 204 operating on the memory. Verifying mechanism 308 verifies that the observed state of the memory is correct after garbage collection operations by garbage collector under test 204. Memory interface 310 duplicates the interfaces between platform-independent virtual machine 102 and memory manager 106, thereby allowing the trace of valid memory transactions to test each interface with memory manager 106 and garbage collector under test 204.

[0035] Testing a Garbage Collector

[0036]FIG. 4 is a flowchart illustrating the process of testing a garbage collector in accordance with an embodiment of the present invention. The system starts when receiving mechanism 302 receives a trace of valid memory transactions from trace storage 110 (step 402). Next, replaying mechanism 304 replays an instruction from the trace of valid memory transactions through memory interface 310 (step 404).

[0037] Observing mechanism then observes the results of the instruction and operations by garbage collector under test 204 (step 406). Verifying mechanism 308 determines if these results are correct by comparing the results with the known results from trace storage 110 (step 408). In one embodiment of the present invention, trace storage 110 includes the read transactions from memory manager 106 and the results of these read transactions. Verifying mechanism 308 compares the results of the replayed read transactions with the results of the read transactions stored in trace storage 110. If the results are incorrect at 408, indicating an error in garbage collector under test 204, test harness 202 generates an error message (step 412).

[0038] After verifying the results as correct at 408 or after generating an error message at 412, test harness 202 determines if there are any more instructions in the trace of valid memory instructions (step 410). If so, the system returns to 404 to continue processing instructions, otherwise, the process is ended.

[0039] The foregoing descriptions of embodiments of the present invention have been presented for purposes of illustration and description only. They are not intended to be exhaustive or to limit the present invention to the forms disclosed. Accordingly, many modifications and variations will be apparent to practitioners skilled in the art. Additionally, the above disclosure is not intended to limit the present invention. The scope of the present invention is defined by the appended claims. 

What is claimed is:
 1. A method to facilitate testing of garbage collection implementations, comprising: receiving a trace of valid memory transactions at a test harness; replaying the trace of valid memory transactions through the test harness into a memory manager, wherein the memory manager includes a garbage collection implementation under test; observing a result of replaying the trace of valid memory transactions on a memory; and verifying that the garbage collection implementation under test does not erroneously change a content of the memory.
 2. The method of claim 1, wherein the trace of valid memory transactions includes memory transactions associated with a plurality of platform-independent computer programs executing on a platform-independent virtual machine.
 3. The method of claim 1, wherein the test harness includes an interface for each entry point into the memory manager.
 4. The method of claim 1, wherein a second garbage collection implementation under test is substituted for the garbage collection implementation under test, whereby multiple garbage collection implementations may be tested.
 5. The method of claim 1, wherein verifying that the garbage collection implementation under test does not erroneously change the content of the memory includes comparing a current state of the memory with a recorded state of memory stored with the trace of valid memory transactions.
 6. The method of claim 1, further comprising gathering the trace of valid memory transactions using a tracing platform-independent virtual machine.
 7. The method of claim 6, wherein the tracing platform-independent virtual machine is known to operate correctly.
 8. A computer-readable storage medium storing instructions that when executed by a computer cause the computer to perform a method to facilitate testing of garbage collection implementations, the method comprising: receiving a trace of valid memory transactions at a test harness; replaying the trace of valid memory transactions through the test harness into a memory manager, wherein the memory manager includes a garbage collection implementation under test; observing a result of replaying the trace of valid memory transactions on a memory; and verifying that the garbage collection implementation under test does not erroneously change a content of the memory.
 9. The computer-readable storage medium of claim 8, wherein the trace of valid memory transactions includes memory transactions associated with a plurality of platform-independent computer programs executing on a platform-independent virtual machine.
 10. The computer-readable storage medium of claim 8, wherein the test harness includes an interface for each entry point into the memory manager.
 11. The computer-readable storage medium of claim 8, wherein a second garbage collection implementation under test is substituted for the garbage collection implementation under test, whereby multiple garbage collection implementations may be tested.
 12. The computer-readable storage medium of claim 8, wherein verifying that the garbage collection implementation under test does not erroneously change the content of the memory includes comparing a current state of the memory with a recorded state of memory stored with the trace of valid memory transactions.
 13. The computer-readable storage medium of claim 8, the method further comprising gathering the trace of valid memory transactions using a tracing platform-independent virtual machine.
 14. The computer-readable storage medium of claim 13, wherein the tracing platform-independent virtual machine is known to operate correctly.
 15. An apparatus to facilitate testing of garbage collection implementations, comprising: a receiving mechanism that is configured to receive a trace of valid memory transactions at a test harness; a replaying mechanism that is configured to replay the trace of valid memory transactions through the test harness into a memory manager, wherein the memory manager includes a garbage collection implementation under test; an observing mechanism that is configured to observe a result of replaying the trace of valid memory transactions on a memory; and a verifying mechanism that is configured to verify that the garbage collection implementation under test does not erroneously change a content of the memory.
 16. The apparatus of claim 15, wherein the trace of valid memory transactions includes memory transactions associated with a plurality of platform-independent computer programs executing on a platform-independent virtual machine.
 17. The apparatus of claim 15, wherein the test harness includes an interface for each entry point into the memory manager.
 18. The apparatus of claim 15, wherein a second garbage collection implementation under test is substituted for the garbage collection implementation under test, whereby multiple garbage collection implementations may be tested.
 19. The apparatus of claim 15, further comprising a comparing mechanism that is configured to compare a current state of the memory with a recorded state of memory stored with the trace of valid memory transactions.
 20. The apparatus of claim 15, further comprising a gathering mechanism that is configured to gather the trace of valid memory transactions using a tracing platform-independent virtual machine.
 21. The apparatus of claim 20, wherein the tracing platform-independent virtual machine is known to operate correctly. 